<?php

class MessageModel extends Model {
    public $tableName = "message";

    protected $has_many = array('hm_messagebody');

    public static $STATUS_UNREAD = 0;
    public static $STATUS_READ = 1;

    public function __construct() {
        parent::__construct();
    }

    public function getSubject() {
        
    }

    public function getUserInvolved() {
        $relations = Model::getRowsFromQuery("SELECT * FROM `message_user` WHERE `message_id` = ".$this->id.";");
        $retval = array();
        foreach ($relations as $r) {
            $model = Model::factory('auth' , $r['user_id']);
            $retval[] = $model;
        }
        return $retval;
    }

    public function addUserInvolved($user) {
        $this->query("INSERT INTO `message_user`(`message_id` , `user_id` , `status`) VALUES(".$this->id." , ".$user->id." , 0);");
    }

    public function getMessageBody() {
        
    }
}

?>
